// 切换拼团点
import { Text, View, Picker, Navigator } from '@tarojs/components';
import './Change.scss'
// icon
import { AtIcon } from 'taro-ui';
import Taro from '@tarojs/taro';
import { useState, useEffect } from 'react';
import http from '../../../utils/http'
import store from '../../../store'
import { observer } from 'mobx-react';
const Change = () => {
    const [list, setList] = useState([])

    // 页面一上来就加载商品数据
    useEffect(() => {
        http({
            url: '/user/groupCommunityQueryList',
            method: 'get',
            header: {
                'token': Taro.getStorageSync('token')
            },
            data: {
                communityName: Taro.getStorageInfoSync('communityName')
            },
        }).then((res) => {
            setList([...res.data.data])
        })
    }, [])
    useEffect(() => {
        // console.log(list)
    }, [list])
    useEffect(() => {
        // console.log(limt)
    }, [limt])


    // 点击修改位置 Taro.getStorageInfoSync('arr')
    let [address, setAddress] = useState()
    const onChange = (e) => {
        setAddress(e.detail.value[0] + e.detail.value[1] + e.detail.value[2])

    }
    const [limt, setLimt] = useState([])
    const showCom = function (v) {
        console.log(v);
        // store.setLimt(v)
        Taro.setStorageSync("limt", v)

        // console.log(store.limt);
        setLimt([v])

        // console.log(setLimt([v]));
        Taro.setStorageSync('limts', v)
        console.log(v);
        console.log(Taro.setStorageSync('limts'));
        Taro.reLaunch({
            url: "../Community/Community"
        })
    }
    console.log(limt);
    const ComTit = () => {
        if (!limt.length) {
            return <View className='com_one' >
                <View className='group_name'>
                    <Text>社区名称</Text>

                </View>
                <View className='com_msg'>
                    <Text>成员：200人</Text> | <Text>团长：</Text> <Text className='at-icon at-icon-phone'></Text>
                </View>
            </View>
        } else {
            return limt.map((v, i) => {
                return (
                    <View className='com_one' key={i} >
                        <View className='group_name'>
                            <Text>{v.communityName}</Text>                    <Text onClick={() => {
                                Taro.reLaunch({
                                    url: "../Community/Community"
                                })
                            }}>切换拼团点</Text>
                        </View>
                        <View className='com_msg'>
                            <Text>成员：200人</Text> | <Text>团长：{v.psName}</Text> <Text className='at-icon at-icon-phone'>{v.psPhone}</Text>
                        </View>
                    </View>
                )
            })
        }
    }

    return <View>
        <ComTit></ComTit>
        <View className='at-row location'>
            <View className='at-col at-col-8'>你当前的地址：{address}</View>
            <View className='at-col at-col-3'>
                <Picker mode='region' onChange={onChange.bind(this)}>
                    <View className='picker'>
                        修改位置
                    </View>
                </Picker>
            </View>
        </View>

        <View className='at-row location'>附近2km范围内的社区</View>
        {list.map((v, i) => {
            return (
                <View className='com_two' key={i} onClick={showCom.bind(this, v)}>
                    <View className='group_name'>
                        <Text>{v.communityName}</Text>
                        <Text className='at-icon at-icon-reload'></Text>
                    </View>
                    <View className='com_msg'>
                        <Text>成员：200人</Text> | <Text>团长：{v.psName}</Text> <Text className='at-icon at-icon-phone'>{v.psPhone}</Text>
                    </View>
                </View>
            )
        })}


    </View>
}
export default observer(Change);

